HackerRank Xor-sequence
提出
Terminated due to timeout :(
code: python
import math
import os
import random
import re
import sys
# Complete the xorSequence function below.
# A1 = A0 xor 1, A2 = A1 xor 2
def xorSequence(l, r):
for i in range(1, 1000000):
for i in range(l+1, r+1):
return tmp
if __name__ == '__main__':
q = int(input())
for q_itr in range(q):
lr = input().split()
result = xorSequence(l, r)
fptr.write(str(result) + '\n')
fptr.close()
解答
code: python
import math
import os
import random
import re
import sys
# 0 1 3 0 4 1 7 0
# 0 1 2 2 6 7 0 0
# Complete the xorSequence function below.
def xorSequence(l, r):
def fun(number):
n = number % 8
if n == 0 or n == 1:
return number
elif n == 2 or n == 3:
return 2
elif n == 4 or n == 5:
return number + 2
else:
return 0
return fun(r) ^ fun(l-1)
if __name__ == '__main__':
q = int(input())
for q_itr in range(q):
lr = input().split()
result = xorSequence(l, r)
fptr.write(str(result) + '\n')
fptr.close()
メモ
https://www.youtube.com/watch?v=OTyoIryc-EY